package com.tudouji.project.customer.controller;

import com.tudouji.common.utils.poi.ExcelUtil;
import com.tudouji.framework.aspectj.lang.annotation.Log;
import com.tudouji.framework.aspectj.lang.enums.BusinessType;
import com.tudouji.framework.web.controller.BaseController;
import com.tudouji.framework.web.domain.AjaxResult;
import com.tudouji.framework.web.page.TableDataInfo;
import com.tudouji.project.customer.domain.Cashflow;
import com.tudouji.project.customer.service.ICashflowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 账户余额流水Controller
 *
 * @author tudouji
 * @date 2022-05-19
 */
@RestController
@RequestMapping("/customer/cashflow")
public class CashflowController extends BaseController
{
    @Autowired
    private ICashflowService cashflowService;

    /**
     * 查询账户余额流水列表
     */
    @GetMapping("/list")
    public TableDataInfo list(Cashflow cashflow)
    {
        startPage();
        List<Cashflow> list = cashflowService.selectCashflowList(cashflow);
        return getDataTable(list);
    }

    /**
     * 导出账户余额流水列表
     */
    @PreAuthorize("@ss.hasPermi('customer:cashflow:export')")
    @Log(title = "账户余额流水", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Cashflow cashflow)
    {
        List<Cashflow> list = cashflowService.selectCashflowList(cashflow);
        ExcelUtil<Cashflow> util = new ExcelUtil<Cashflow>(Cashflow.class);
        return util.exportExcel(list, "cashflow");
    }

    /**
     * 获取账户余额流水详细信息
     */
    @PreAuthorize("@ss.hasPermi('customer:cashflow:query')")
    @GetMapping(value = "/{guid}")
    public AjaxResult getInfo(@PathVariable("guid") String guid)
    {
        return AjaxResult.success(cashflowService.selectCashflowById(guid));
    }

    /**
     * 新增账户余额流水
     */
    @PreAuthorize("@ss.hasPermi('customer:cashflow:add')")
    @Log(title = "账户余额流水", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Cashflow cashflow)
    {
        return toAjax(cashflowService.insertCashflow(cashflow));
    }

    /**
     * 修改账户余额流水
     */
    @PreAuthorize("@ss.hasPermi('customer:cashflow:edit')")
    @Log(title = "账户余额流水", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Cashflow cashflow)
    {
        return toAjax(cashflowService.updateCashflow(cashflow));
    }

    /**
     * 删除账户余额流水
     */
    @PreAuthorize("@ss.hasPermi('customer:cashflow:remove')")
    @Log(title = "账户余额流水", businessType = BusinessType.DELETE)
	@DeleteMapping("/{guids}")
    public AjaxResult remove(@PathVariable String[] guids)
    {
        return toAjax(cashflowService.deleteCashflowByIds(guids));
    }
}
